/**
 * 个人中心
 */
bangkeapp.factory('safeService', ['$http', '$q', 'url', 'userinfoService', '$ionicLoading',
	function($http, $q, url, userinfoService, $ionicLoading) {
		
		var updatepwd = function(member) {

			var result = {};

			var data = userinfoService.getData();
			data.request.body.member = []
			data.request.body.member[0] = member;

			var deferred = $q.defer();
			var promise = deferred.promise;
			var progress;
			// 修改密码
			$http({
				method: "JSONP",
				url: url + "/updatepwd/update?callback=JSON_CALLBACK",
				params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {

				result = response;
				if(response.Response.Header.ResponseCode == "M") {
					userinfoService.setUser(response.Response.Body.Response[0]);
				}
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
				result.interests = 0;
			});
			return promise;
		}
		var saveorupdatesecurepwd = function(password) {

			var result = {};
			var data = userinfoService.getNewData();
			data.body = password;

			var deferred = $q.defer();
			var promise = deferred.promise;
			var progress;
			// 修改密码
			$http({
				method: "JSONP",
				url: url + "/securepwdchange/saveOrUpdateSecurePWD?callback=JSON_CALLBACK",
				params: {
					"body": angular.toJson(data)
				}
			}).success(function(response) {
				result = response;
				deferred.notify(progress);
				deferred.resolve(result);
			})
			.error(function(error) {
				deferred.reject(error);
				result.interests = 0;
			});
			return promise;
		}
		return {
			updatepwd: updatepwd,
			saveorupdatesecurepwd : saveorupdatesecurepwd
		};
	}
]);